You are here: Scripting Reference > Variables > Global Datasets

Global Datasets

The special global datasets (Data1, Data2, etc, through to over Data40 in recent versions) are automatically declared within the script engine for Maps (but not for Custom Scripts). You do not need to declare these yourself to use them. They are (pre-)declared as:

var Data1 : TFloClientDataSet;

var Data2 : TFloClientDataSet;

...

var Data10 : TFloClientDataSet

... (since Flow version 230c)

var Data35 : TFloClientDataSet;

...

To provide dataset names that are more helpful than "Data1", "Data2", etc, many of the numbered Global Datasets also have a purpose-oriented alias. For example, Data6 has the alias DATA_Company, and Data11 has the alias DATA_Product.These are aliases for the same underlying dataset object, therefore an update to DATA_Company is also an update to Data6 (and vice versa). See Global Dataset Aliases for the list of dataset aliases.

The global datasets are populated with data by the user calling the See "Database" functions. The global datasets are of the See "Data Set" class - refer to this class for more information on what they can be used for.

Once populated with data you can access its fields like any other dataset e.g. Data1['FieldName'].Value. (Refer to See "Referencing Fields").

The global datasets are global to each execution of a Map, but they are not shared between Maps (or even between different executions of the same Map). Each Map contains its own set of global datasets. Therefore if you have two Maps and within one you populate Data1, you will not be able to access this dataset through Data1 in the second Map.

Since a global dataset is global to the Map, you can populate it in one event and reference it from another. Therefore if within field 1 OnMap you populate Data1, you can read this dataset from field 2 OnMap.

Global datasets are naturally persistent. This means they will remain populated with data for the entire execution of the Map (or until your close it or repopulate it). However the next execution of the Map will have its own set of global datasets that start unpopulated.

An example of using global datasets is:

procedure ScriptEvent (var Value : variant);

begin

GetDataSetFromSource(Data1,'select accno, name from accounts where accno=10',0);

if Data1.EOF then

LogError('Unable to find account with account number 10')

else

Value := Data1['accno'].Value;

end;

procedure ScriptEvent (var Value : variant);

begin

Value := Data1['name'].AsString;

end;

The above two scripts form one example. In this example, the Data1 dataset is populated with data by performing a bespoke SQL call through the source data definition. A check is made to determine whether any data was returned (Data1.EOF is True if no data is found), and then the values of the returned fields are used. The second script is using the name field from the Data1 dataset that was populated in an earlier event.

To close/reset a global dataset within a Map, use Data1.Active := False;